/* eslint-disable */
import legacyPlugin from '@vitejs/plugin-legacy';
import usePluginImport from 'vite-plugin-importer';
import * as path from 'path';
import vitePluginReactJsSupport from 'vite-plugin-react-js-support';
import reactRefresh from '@vitejs/plugin-react-refresh';
// @see https://cn.vitejs.dev/config/
export default ({
  command,
  mode
}) => {
  let rollupOptions = {};
  if (command === 'serve') {
    rollupOptions.input = [];
  }

  let optimizeDeps = {};
  if (command === 'serve') {
    optimizeDeps.entries = false;
  }

  let alias = {
    'react-native': 'react-native-web',
    '@': path.resolve(__dirname, '.\src'),
    '@assets': path.resolve(__dirname, '.\src\assets'),
    '@css': path.resolve(__dirname, '.\src\assets\css'),
    '@img': path.resolve(__dirname, '.\src\assets\images'),
    '@js': path.resolve(__dirname, '.\src\assets\js'),
    '@com': path.resolve(__dirname, '.\src\common'),
    // '@utils': path.resolve(__dirname, '.\src\common\utils'),
    '@cpt': path.resolve(__dirname, '.\src\global\component'),
    '@tp': path.resolve(__dirname, '.\src\global\template'),
    '@plugin': path.resolve(__dirname, '.\src\global\plugin'),
    '@antd': path.resolve(__dirname, '.\src\global\plugin\antd'),
    '@mu': path.resolve(__dirname, '.\src\global\plugin\material-ui'),
    '@es': path.resolve(__dirname, '.\src\global\plugin\echarts'),
    '#private': path.resolve(__dirname, '.\src\private'),
    '#cpt': path.resolve(__dirname, '.\src\private\component'),
    '#tp': path.resolve(__dirname, '.\src\private\template'),
    '#plugin': path.resolve(__dirname, '.\src\private\plugin'),
    '#page': path.resolve(__dirname, '.\src\private\page'),
    '#frame': path.resolve(__dirname, '.\src\private\frame'),
    '@views': path.resolve(__dirname, '.\src\views'),
    '@pages': path.resolve(__dirname, '.\src\views-pages'),
  }

  let proxy = {}

  let define = {
    'process.env.APP_IS_LOCAL': '"true"',
  }

  let esbuild = {}

  return {
    base: './', // index.html文件所在位置
    root: './', // js导入的资源路径，src
    resolve: {
      alias,
    },
    define: define,
    server: {
		host: '127.0.0.1',	// 主机
		port: 3001,			// 端口
		open: true,			// 是否自动开启浏览器
		https: false,		// 
		cors: true,			// 允许跨域
      // 代理
      proxy,
    },
    build: {
      target: 'es2015',
      minify: 'terser', // 是否进行压缩,boolean | 'terser' | 'esbuild',默认使用terser
      manifest: false, // 是否产出maifest.json
      sourcemap: false, // 是否产出soucemap.json
      outDir: 'build', // 产出目录
      rollupOptions,
    },
    esbuild,
    optimizeDeps,
    plugins: [
      legacyPlugin({
        targets: ['Android > 39', 'Chrome >= 60', 'Safari >= 10.1', 'iOS >= 10.3', 'Firefox >= 54', 'Edge >= 15'],
      }), usePluginImport({
        libraryName: "antd", // todo please input your babel-plugin-import config
        libraryDirectory: "es",
        style: true,
      }), vitePluginReactJsSupport([], {
        jsxInject: true,
      }), reactRefresh(),
	  
    ],
    css: {
      preprocessorOptions: {
        less: {
          // 支持内联 JavaScript
          javascriptEnabled: true,
		  modifyVars: { '@primary-color': '#208fa0' }
        }
      }
    },
  }
}